<?php
/**
 * Created by PhpStorm.
 * User: wangj
 * Date: 2020-09-29
 * Time: 15:26
 */
namespace common\models;
use Yii;
use common\models\BaseModel;


class BalancePriceLog extends BaseModel
{

    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'balance_price_log';
    }


    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['price'], 'required'],
            [['btype'], 'required'],
            [['btype'], 'integer'],
            [['price'], 'number'],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'price' => '当日币价',
            'create_time' => '日期',
            'btype' => '操作账本类型',
        ];
    }

    /*
        * data list
        * @param whereArr 条件
        * @param params 基本参数 包含 field order page limit
        * @param extends  扩展信息 一些相关的信息
        * return array
    */
    public static function dataList($whereArr, $params, $extends = array())
    {
        $model  = self::find();
        $where  = isset($whereArr['where']) ? $whereArr['where'] : [];
        $whereAnd = isset($whereArr['and']) ? $whereArr['and'] : [];
        $models = self::queryFormart($model, $where, $params, $whereAnd);
        $model  = $models['model'];
        self::$totalNums = $models['totalNums'];
        self::$query = $models['query'];

        $data  = $model->asarray()->all();
        if(empty($data)) return array();
        if(empty($extends)) return $data;
        foreach($extends as $ext)
        {
            ## 获取需要的扩展信息

        }
        return $data;
    }


    public static function getOne($where, $field = ['*'])
    {
        return self::find()->select($field)->where($where)->asarray()->one();
    }


    public static function getAll($where, $field = ['*'])
    {
        return self::find()->select($field)->where($where)->asarray()->all();
    }

}